package org.smart4j.charpter2.service;

import java.util.List;
import java.util.Map;

import org.smart4j.charpter2.helper.DatabaseHelper;
import org.smart4j.charpter2.model.Customer;

/**
 * 提供客户数据服务
 * @author 蒋贵强
 */
public class CustomerService {

	/**
	 * 获取客户列表
	 * @param keyWord
	 * @return
	 */
	public List<Customer> getCustomerList(String keyWord){
		String sql = "select * from customer a where a.name=?";
		return DatabaseHelper.queryEntityList(Customer.class, sql, keyWord);
	}
	
	/**
	 * 根据ID获取客户详情
	 * @param id
	 * @return
	 */
	public Customer getCustomerDetail(long id){
		
		String sql = "select * from customer a where a.id=?";
		return DatabaseHelper.queryEntity(Customer.class, sql, id);
	}
	
	/**
	 * 创建客户
	 * @param fieldMap
	 * @return
	 */
	public boolean createCustomer(Map<String,Object> fieldMap){
		return DatabaseHelper.insertEntity(Customer.class, fieldMap);
	}
	
	/**
	 * 更新客户
	 * @param id
	 * @param fieldMap
	 * @return
	 */
	public boolean updateCustomer(long id,Map<String,Object> fieldMap){
		return DatabaseHelper.updateEntity(Customer.class, id, fieldMap);
	}
	
	/**
	 * 删除客户
	 * @param id
	 * @return
	 */
	public boolean deleteCustomer(long id){
		return DatabaseHelper.deleteEntity(Customer.class, id);
	}
}
